<template>
    <div class="background">
        <form>
            <div class="input-row">
                <div class="input-container">
                    <textarea :rows="calculateRows" placeholder="在此处输入..." required v-model="inputValue"
                        class="transparent-input" style="resize: none;overflow-y: auto;"
                        @keydown.enter.prevent="handleEnterKey($event)"></textarea>
                </div>
                <el-button @click="sendMessage" class="transparent-button" style="margin-right: 15px;">
                    <el-icon style="font-size: 24px;color: orange;">
                        <Promotion />
                    </el-icon>
                </el-button>
            </div>
        </form>
    </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';

const inputValue = ref('');
const emit = defineEmits(['submit']);

function sendMessage() {
    console.log(inputValue.value);
    // Add your logic for sending the message here
    emit('submit', inputValue.value);
    inputValue.value = '';
}
function handleEnterKey(event: KeyboardEvent) {
    if (!event.ctrlKey) {
        sendMessage();
    }
}
const calculateRows = computed(() => {
    const lines = inputValue.value.split('\n').length;
    return Math.min(Math.max(lines, 1), 2);
});


</script>

<style scoped>
.input-row {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Add this line to center the input-row horizontally */
    border-radius: 20px;
    border: 2px solid #333333;
    overflow: hidden;
}

.input-container {
    flex: 1;
    padding: 0 10px;
    display: flex;
    align-items: center;
    /* Add this line to center the input-container vertically */
}

.transparent-input {
    background-color: transparent;
    border: none;
    width: 100%;
    box-shadow: none;
    color: grey;
    outline: none;
    font-size: large;
    /* Add this line to remove the border on input focus */
    max-height: 50px;
}

.transparent-button {
    background-color: rgba(255, 255, 255, 0);
    color: white;
    text-align: center;
    border-radius: 100%;
    border: none;
    padding: 0;
    width: 30px;
}

.transparent-button:hover {
    transform: scale(1.2);
}

.transparent-button:active {
    animation: click 0.5s;
}

@keyframes click {
    0% {
        transform: scale(1.2);
    }

    50% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
    }
}
</style>
